package com.seal.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.seal.dao.BaseDaoImpl;
import com.seal.dao.INoteInfoDao;
import com.seal.model.NoteInfo;

@Repository("noteInfoDaoImpl")
public class NoteInfoDaoImpl extends BaseDaoImpl implements INoteInfoDao {

	public void addNoteInfo(NoteInfo ca) throws Exception {
		this.save(ca);
	}

	public NoteInfo getNoteInfo(Long busiNo, String userId)
			throws Exception {
		String hql = "from NoteInfo t where t.busiNo=? and t.createUserid=?";
		Query query = this.getSession().createQuery(hql)
			.setLong(0, busiNo)
			.setString(1, userId);
		List list=query.list();
		if(list.size()==1)
			return (NoteInfo)list.get(0);
		return null;
	}
	
	public List<NoteInfo> getNoteInfoList(String busiNos, String userId)
		throws Exception {
		String hql = "from NoteInfo t where t.busiNo in("+busiNos+") and t.createUserid=?";
		Query query = this.getSession().createQuery(hql)
			.setString(0, userId);
		return query.list();
	}

	public NoteInfo getNoteInfoById(Long id) throws Exception {
		return (NoteInfo) this.select(NoteInfo.class, id);
	}
	
	public void updateNoteInfo(NoteInfo ca) throws Exception {
		this.update(ca);
	}
}
